package com.baizhi.service.impl;
import com.baizhi.dao.AdminMapper;
import com.baizhi.entity.Admin;
import com.baizhi.service.AdminService;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.sql.Wrapper;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: renpu
 * @Date: 2019/2/26 20:17
 * @Description:
 */
@Service
@Transactional
public class AdminServiceImpl implements AdminService {

    @Autowired
    private AdminMapper adminMapper;

    @Override
    public Admin selectOne(Admin admin) {
       QueryWrapper<Admin> wrapper=new QueryWrapper<>();
        wrapper.eq("username",admin.getUsername()).eq("password",admin.getPassword());
        return adminMapper.selectOne(wrapper);
    }

    @Override
    public void updatePassword(Admin admin) {
        adminMapper.updateById(admin);
    }

    @Override
    public void insert(Admin admin) {
        adminMapper.insert(admin);

    }

    @Override
    public void delete(int id) {
        adminMapper.deleteById(id);
    }

    @Override
    public Map selectAdmin(int rows, int page) {

        Map map=new HashMap();
        IPage<Admin> iPage=new Page(rows,page);

        IPage<Admin> adminIPage=adminMapper.selectPage(iPage,null);
        List<Admin> list=adminIPage.getRecords();
        long count=adminIPage.getTotal();
        map.put("rows",list);
        map.put("total",count);
        return map;
    }
}
